home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / RGASM.RAR / ASMCODE.EXE / CHAPT7 / KEYBSERV.ASM < prev    next >
Encoding:
Assembly Source File  |  1993-05-10  |  5.6 KB  |  144 lines

  1. ;
  2. ;       Program KeybServ ( Chapter 7 )
  3. ;
  4.     option  oldmacros
  5.     page    55,132
  6.     NAME    KeybServ
  7.     INCLUDE EXTENDA.INC
  8. BiosDat segment at 40h
  9.     org     17h
  10. KbdFl1  db      ?
  11. KbdFl2  db      ?
  12.     org     96h
  13. KbdFl3  db      ?
  14. BiosDat ends
  15.  
  16.     CODESEG KeybServ
  17.     DATASEG
  18.  
  19.     CLpublic <IsKbdEnh, GnumLock, GCapsLock, SNumLock, SCapsLock>
  20.     CLstatic
  21.  
  22. $define FALSE   0000h
  23. $define TRUE    0001h
  24. KbdRDF  db      00h                     ; Read Character function number
  25. KbdGSF  db      01h                     ; Get Status function number
  26. KbdGFF  db      02h                     ; Get Flag function number
  27. IndEnh  db      0
  28. CNumL   equ     20h
  29. CCapL   equ     40h
  30.  
  31.     WORKFUNCS
  32.  
  33. ChecKbd proc    near
  34. ;
  35. ;       This procedure checks whether an enhanced keyboard is being used.
  36. ;       All registers are preserved after returning from the procedure.
  37. ;       Result: The variable IndEnh (byte) is non-zero.
  38. ;
  39.     push    es                      ; Save the segment register
  40.     push    ax                      ; Save the accumulator register
  41.     mov     ax,BiosDat              ; Address of BIOS data segment
  42.     mov     es,ax                   ; Now ES points to the BIOS data
  43.     mov     al,es:KbdFl3            ; Take the KEYBOARD FLAG 3 ( [0496h] )
  44.     mov     IndEnh,al               ; Store it into the memory
  45.     and     IndEnh,10h              ; Bit 5 - sign of the enhanced keyboard
  46.     pop     ax                      ; Restore the accumulator
  47.     pop     es                      ; Restore the segment register
  48.     ret                             ; Return to the caller
  49. ChecKbd endp
  50.  
  51. GetFl12 proc    near
  52. ;
  53. ;       This procedure extracts the keyboard flags 1 and 2
  54. ;       ( bytes 417h and 418h) from the BIOS data area and puts them
  55. ;       into AX register (AH - flag 1 , AL - flag 2).
  56. ;       All registers except the AX register are preserved after returning
  57. ;       from the procedure.
  58. ;
  59.     push    es                      ; Save the segment register
  60.     mov     ax,BiosDat              ; Address of BIOS data segment
  61.     mov     es,ax                   ; Now ES points to the BIOS data
  62.     mov     ah,es:KbdFl1            ; Take the KEYBOARD FLAG 1 ( [0417h] )
  63.     mov     al,es:KbdFl2            ; Take the KEYBOARD FLAG 2 ( [0418h] )
  64.     pop     es                      ; Restore the segment register
  65.     ret                             ; Return to the caller
  66. GetFl12 endp
  67.  
  68. PutFl12 proc    near
  69. ;
  70. ;       This procedure writes the values from the AX register
  71. ;       (AH - flag 1, AL - flag 2) into the keyboard flags 1 and 2
  72. ;       ( bytes 417h and 418h) in the BIOS data area.
  73. ;       All registers are preserved after returning from this procedure.
  74. ;
  75.     push    es                      ; Save the segment register
  76.     push    ax                      ; Save the work register
  77.     mov     ax,BiosDat              ; Address of BIOS data segment
  78.     mov     es,ax                   ; Now ES points to the BIOS data
  79.     pop     ax                      ; Restore the work register
  80.     mov     es:KbdFl1,ah            ; Put the KEYBOARD FLAG 1 ( [0417h] )
  81.     mov     es:KbdFl2,al            ; Put the KEYBOARD FLAG 2 ( [0418h] )
  82.     pop     es                      ; Restore the segment register
  83.     ret                             ; Return to the caller
  84. PutFl12 endp
  85.  
  86.     ENDWORK
  87.  
  88.     CLfunc  log IsKbdEnh
  89.     CLcode
  90.     mov     ax,FALSE                ; Set the keyboard type to STANDARD
  91.     call    ChecKbd
  92.     cmp     IndEnh,0                ; Is enhanced keyboard present?
  93.     je      IsKbdEnhR               ; If not - return
  94.     mov     ax,TRUE                 ; Set the keyboard type to ENHANCED
  95. IsKbdEnhR:
  96.     CLret   ax                      ; AX contains the value to be returned
  97.  
  98.     CLfunc  log GNumLock
  99.     CLcode
  100.     mov     dx,FALSE                ; Set the NumLock indicator to OFF
  101.     call    GetFl12                 ; Get the Keyboard Flags
  102.     test    ah,CNumL                ; Is the NumLock state on? (bit 5)
  103.     jz      GNumLockR               ; If not - return
  104.     mov     dx,TRUE                 ; Set the NumLock indicator to ON
  105. GNumLockR:
  106.     CLret   dx                      ; DX contains the value to be returned
  107.  
  108.     CLfunc  log GCapsLock
  109.     CLcode
  110.     mov     dx,FALSE                ; Set the CapsLock indicator to OFF
  111.     call    GetFl12                 ; Get the Keyboard Flags
  112.     test    ah,CCapL                ; Is the CapsLock state on?  (bit 6)
  113.     jz      GCapsLockR              ; If not - return
  114.     mov     dx,TRUE                 ; Set the CapsLock indicator to ON
  115. GCapsLockR:
  116.     CLret   dx                      ; DX contains the value to be returned
  117.  
  118.     CLfunc  log SNumLock <int SnlP>
  119.     CLcode
  120.  
  121.     call    GetFl12                 ; Get the Keyboard Flags
  122.     and     ah,not CNumL            ; Clear the NumLock state (bit 5)
  123.     mov     dx,SnlP                 ; Copy the parameter to returned value
  124.     cmp     dx,1                    ; Is it request for setting?
  125.     jne     SNumLockR               ; If not - return
  126.     or      ah,CNumL                ; Set the NumLock state (bit 5)
  127. SNumLockR:
  128.     call    PutFl12                 ; Write the Keyboard Flags
  129.     CLret   dx                      ; DX contains the value to be returned
  130.  
  131.     CLfunc  log SCapslock <int SCplP>
  132.     CLcode
  133.     call    GetFl12                 ; Get the Keyboard Flags
  134.     and     ah,not CCapL            ; Clear the CapsLock state (bit 6)
  135.     mov     dx,SCplP                ; Copy the parameter to returned value
  136.     cmp     dx,1                    ; Is this a request for setting?
  137.     jne     SCapsLockR              ; If not - return
  138.     or      ah,CCapL                ; Set the CapsLock state (bit 6)
  139. SCapsLockR:
  140.     call    PutFl12                 ; Write the Keyboard Flags
  141.     CLret   dx                      ; DX contains the value to be returned
  142.  
  143.         END
  144.